package cn.kust.tarvelService.controller;



import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import cn.kust.tarvelService.pojo.ArticleCategory;
import cn.kust.tarvelService.service.ArticleCategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 分类管理表 前端控制器
 * </p>
 *
 * @author mq
 * @since 2022-07-26
 */
@Api(tags = "文章分类")
@RestController
@RequestMapping("/travelService/article-category")
public class ArticleCategoryController {

  @Autowired
  private ArticleCategoryService categoryService;


    @GetMapping("/listCategory")
    public ResponseResult listCategory(){
     List<ArticleCategory> list = categoryService.list();
     return ResponseResult.success().setData(list);
    }

    @PostMapping("/addCategory")
    public ResponseResult addCategory(@RequestBody ArticleCategory category){
        categoryService.save(category);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delCategory(@PathVariable("id") Long id){
        boolean b = categoryService.removeById(id);
        if(b){
            return ResponseResult.success();
        }
        return ResponseResult.fail(500,"删除分类失败");
    }



}

